<?php
/*=====================================================
 Copyright (C) ETERNAL<iqstar@ms24.hinet.net>
 URL : http://www.et99.net

请仔细阅读以下许可协议。当您使用本软体，您将自动成为本协议的一方并受到本协议的约束。

软体和文档受到台湾及中国大陆著作权法及国际条约的保护。您不得：
a)营利、出租或者出借软体或文档的任何部分。
b)反向工程、分解、反编译或者企图察看软体的源代码作为商业用途。
c)修改或者改变软体，或者与其他程式结合。

许可人保留软体及文档的所有权利和权益。您不能通过本许可协定获得软体的任何所有权和知识产权。
===================================================== */
class wog_act_friend{
	function friend_list($user_id)
	{
		global $DB_site,$lang,$wog_array,$_POST;
		if(empty($_POST["page"]) || !is_numeric($_POST["page"]))
		{
			$_POST["page"]="1";
		}
		$page=(int)$_POST["page"];
		$spage=($page*$wog_array['list_limit'])-$wog_array['list_limit'];
		$time=time()-$wog_array["offline_time"];

		$sql="select count(f_id) from wog_friend_list where p_id=".$user_id;
		$m=$DB_site->query_first($sql);

		$sql="select a.p_id,a.p_name,a.p_lv,a.p_place,a.p_online_time from wog_player a,wog_friend_list b where b.p_id=".$user_id." and a.p_id=b.f_id order by a.p_online_time desc LIMIT ".$spage.",".$wog_array['list_limit'];
		$pack=$DB_site->query($sql);
		$s="";
		$online_set=0;
		while($packs=$DB_site->fetch_array($pack))
		{
			$online_set=($packs[p_online_time]>=$time)?1:0;
			$s.=";".$packs[p_id].",".$packs[p_name].",".$packs[p_lv].",".$packs[p_place].",".$online_set;
		}
		$s=substr($s,1);
		$DB_site->free_result($pack);
		showscript("parent.friend_list('$s',$page,$m[0])");
		unset($s,$pack);
	}
	function friend_del($user_id)
	{
		global $DB_site,$_POST;
		$id=$_POST["temp_id"];
		$sql="delete from  wog_friend_list where p_id=$user_id and f_id=$id";
		$DB_site->query($sql);
		$this->friend_list($user_id);
	}
	function friend_add($user_id)
	{
		global $DB_site,$lang,$_POST,$wog_array;
		$name=addslashes(htmlspecialchars($_POST["name"]));
		if(empty($name))
		{
			alertWindowMsg($lang['wog_act_message_er1']);
		}
		$to_p=$DB_site->query_first("SELECT p_id FROM wog_player WHERE p_name='".$name."'");
		if($to_p[p_id]==$user_id)
		{
			alertWindowMsg($lang['wog_act_friend_er2']);
		}
		$sql="select p_id from wog_friend_list where p_id=$user_id and f_id=$to_p[p_id]";
		$check=$DB_site->query_first($sql);
		if($check)
		{
			alertWindowMsg($lang['wog_act_friend_er1']);
		}
		else
		{
			$sql="insert into wog_friend_list(p_id,f_id)values($user_id,$to_p[p_id])";
		}
		$from_p=$DB_site->query_first("SELECT p_name FROM wog_player WHERE p_id=$user_id");
		$DB_site->query($sql);
		$this->friend_list($user_id);
	}
}
?>